/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package longprojectihm;

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import model_package.Log;

/**
 *
 * @author haythem
 */
public class Tree extends JTree {

    public Tree(){
        super();
    }

    public Tree(DefaultMutableTreeNode racine) {
        super(racine);
    }


    public static Tree buildTree(Log l){
                Tree arbre;
		//Création d'une racine
		DefaultMutableTreeNode racine = new DefaultMutableTreeNode(l.getLogID());
                // loop for the cases
                for (int i=0;i<l.getListCases().size();i++){
		//Nous allons ajouter des branches et des feuilles à notre racine
			DefaultMutableTreeNode caseTree = new DefaultMutableTreeNode(l.getListCases().get(i).getCaseID());
                        //lopp for the events
			for(int j = 0; j < l.getListCases().get(i).getEventsList().size(); j++){
					DefaultMutableTreeNode eventTree = new DefaultMutableTreeNode(l.getListCases().get(i).getEventsList().get(j).getEventID());
					//Cette fois, on ajoute nos feuilles
					eventTree.add(new DefaultMutableTreeNode("Task : "+l.getListCases().get(i).getEventsList().get(j).getTask()));
//                                        System.out.println("Task : "+listCases.get(i).getEventsList().get(j).getTask());
                                        eventTree.add(new DefaultMutableTreeNode("Performative : "+l.getListCases().get(i).getEventsList().get(j).getPerfomative()));
//                                        System.out.println("Performative : "+listCases.get(i).getEventsList().get(j).getPerfomative());
                                        eventTree.add(new DefaultMutableTreeNode("Initiator : "+l.getListCases().get(i).getEventsList().get(j).getIniator()));
//                                        System.out.println("Initiator : "+listCases.get(i).getEventsList().get(j).getIniator());
                                        DefaultMutableTreeNode receiversTree = new DefaultMutableTreeNode("receivers");
                                        for(int k=0;k<l.getListCases().get(i).getEventsList().get(j).getListReceivers().size();k++){
                                             receiversTree.add(new DefaultMutableTreeNode("Receiver n°"+k+" : "+l.getListCases().get(i).getEventsList().get(j).getListReceivers().get(k)));
//                                             System.out.println("Receiver n°"+k+" : "+listCases.get(i).getEventsList().get(j).getListReceivers().get(k));
                                        }
                                        eventTree.add(receiversTree);
                                        eventTree.add(new DefaultMutableTreeNode("conversation : "+l.getListCases().get(i).getEventsList().get(j).getConversationID()));
                                        eventTree.add(new DefaultMutableTreeNode("Date : "+l.getListCases().get(i).getEventsList().get(j).getDate().toString()));
//                                        System.out.println("Date : "+listCases.get(i).getEventsList().get(j).getDate().toString());
					caseTree.add(eventTree);
			}

			//On ajoute la feuille ou la branche à la racine
			racine.add(caseTree);

                }
		//On crée, avec notre hiérarchie, un arbre
		arbre = new Tree(racine);


		//Que nous plaçons sur le ContentPane de notre JFrame à l'aide d'un scroll
		//this.getContentPane().add(new JScrollPane(arbre));
                return arbre;
	}

}
